<template>
  <div class="search">
    <el-form
      label-width="80px"
      label-position="left"
      class="form"
      size="large"
      :model="searchFrom"
      ref="elFormRef"
    >
      <!-- 表单-->
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="用户名" class="form-item" prop="name" :clearable="true">
            <el-input placeholder="请输入部门名称" v-model="searchFrom.name" :clearable="true" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="真实姓名" class="form-item" prop="leader" clearable>
            <el-input placeholder="请输入部门领导的名称" v-model="searchFrom.leader" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="创建时间" class="form-item" prop="createAt">
            <el-date-picker
              type="daterange"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              v-model="searchFrom.createAt"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8"> </el-col>
      </el-row>

      <!-- 按钮 -->
      <div class="btns">
        <el-button type="info" size="large" icon="Delete" @click="resetClick">重置</el-button>
        <el-button type="primary" size="large" icon="Search" @click="searchClick">搜索</el-button>
      </div>
    </el-form>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref, defineEmits } from 'vue'
import type { ElForm } from 'element-plus'

const emits = defineEmits(['queryClick', 'resetClick'])

const searchFrom = reactive({
  name: '',
  leader: '',
  createAt: ''
})

const elFormRef = ref<InstanceType<typeof ElForm>>()

function searchClick() {
  emits('queryClick', searchFrom)
}
function resetClick() {
  elFormRef.value.resetFields()
  emits('resetClick')
}
</script>

<style lang="scss" scoped>
.search {
  background-color: #fff;
  padding: 20px;
  .el-form-item {
    padding: 20px 30px;
    margin-bottom: 0;
  }
  .btns {
    text-align: right;
    padding: 0 50px 10px 0;
  }
}
</style>
